package com.blog.utils.taglib;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.BodyTagSupport;

/**
 * <style type="text/css"> 
 * ._xtop, ._xbottom {display:block; background:transparent; font-size:1px;} 
 * ._xb1, ._xb2, ._xb3, ._xb4 {display:block; overflow:hidden;} 
 * ._xb1, ._xb2, ._xb3 {height:1px;} 
 * ._xb2, ._xb3, ._xb4, ._xboxcontent {background:#CFEFFF; border-left:1px solid #08c; border-right:1px  solid #08c;} 
 * ._xb1 {margin:0 5px; background:#08c;} 
 * ._xb2 {margin:0 3px; border-width:0 2px;} 
 * ._xb3 {margin:0 2px;} 
 * ._xb4 {height:2px; margin:0 1px;}
 * </style>
 * 
 * @author ZhangBo
 * 
 */
public class BoxTag extends BodyTagSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 6870266923919351829L;

	private String borderColor = "#08c";//边框颜色
	private String backgroundColor = "#CFEFFF";//背景颜色
	private int borderRadius = 4;//弧度
	private boolean customStyle = false;//使用自定义样式
	//private boolean fill = false;

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
	 */
	@Override
	public int doEndTag() throws JspException {
		
		StringBuffer buffer = new StringBuffer();
		
		// 定义样式
		buffer.append("<style type='text/css'>\r\n");
		buffer.append("._xtop, ._xbottom {display:block; background:transparent; font-size:1px;}\r\n");
		buffer.append("._xb1, ._xb2, ._xb3, ._xb4 {display:block; overflow:hidden;}\r\n");
		buffer.append("._xb1, ._xb2, ._xb3 {height:1px;}\r\n ");
		buffer.append("._xb2, ._xb3, ._xb4, ._xboxcontent {display:block;background:"+backgroundColor+"; border-left:1px solid "+borderColor+"; border-right:1px  solid "+borderColor+";}\r\n");
		
		buffer.append("._xb1 {margin:0 5px; background:"+borderColor+";}\r\n ");
		buffer.append("._xb2 {margin:0 3px; border-width:0 2px;}\r\n ");
		buffer.append("._xb3 {margin:0 2px;}\r\n ");
		buffer.append("._xb4 {height:2px; margin:0 1px;}\r\n ");
		buffer.append("._xboxcontent {}\r\n ");
		buffer.append("</style>\r\n");
		
		//HTML代码
		buffer.append("<b class='_xtop'><b class='_xb1'></b><b class='_xb2'></b><b class='_xb3'></b><b class='_xb4'></b></b>\r\n");
		buffer.append("<div class='_xboxcontent'>");
		buffer.append("<div style='height: 0.5'></div>");
		buffer.append(getBodyContent().getString());
		buffer.append("<div style='height: 0.5'></div>");
		buffer.append("</div>");
		buffer.append("<b class='_xbottom'><b class='_xb4'></b><b class='_xb3'></b><b class='_xb2'></b><b class='_xb1'></b></b>\r\n");
		buffer.append("\r\n");
		try {
			this.pageContext.getOut().println(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
	
	
	
	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.BodyTagSupport#getBodyContent()
	 */
	@Override
	public BodyContent getBodyContent() {
		return super.getBodyContent();
	}



	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.BodyTagSupport#setBodyContent(javax.servlet.jsp.tagext.BodyContent)
	 */
	@Override
	public void setBodyContent(BodyContent b) {
		super.setBodyContent(b);
	}



	/**
	 * @return the borderColor
	 */
	public String getBorderColor() {
		return borderColor;
	}



	/**
	 * @param borderColor the borderColor to set
	 */
	public void setBorderColor(String borderColor) {
		this.borderColor = borderColor;
	}



	/**
	 * @return the backgroundColor
	 */
	public String getBackgroundColor() {
		return backgroundColor;
	}



	/**
	 * @param backgroundColor the backgroundColor to set
	 */
	public void setBackgroundColor(String backgroundColor) {
		this.backgroundColor = backgroundColor;
	}



	/**
	 * @return the borderRadius
	 */
	public int getBorderRadius() {
		return borderRadius;
	}



	/**
	 * @param borderRadius the borderRadius to set
	 */
	public void setBorderRadius(int borderRadius) {
		this.borderRadius = borderRadius;
	}



	/**
	 * @return the customStyle
	 */
	public boolean isCustomStyle() {
		return customStyle;
	}



	/**
	 * @param customStyle the customStyle to set
	 */
	public void setCustomStyle(boolean customStyle) {
		this.customStyle = customStyle;
	}
}
